package com.jhgk.jhcee.forecast.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jhgk.jhcee.bfk.mapper.PtzsjhMapper;
import com.jhgk.jhcee.bfk.model.Ptzsjh;
import com.jhgk.jhcee.bfk.model.PtzsjhExample;
import com.jhgk.jhcee.common.enums.BasisResultEnum;
import com.jhgk.jhcee.common.resultful.BasisResultful;
import com.jhgk.jhcee.common.resultful.PageResultful;
import com.jhgk.jhcee.forecast.domain.model.PtzsjhModel;
import com.jhgk.jhcee.forecast.service.PtzsjhService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: xiezhongping
 * @description:
 * @date: 2021/8/11 14:35.
 */
@Service(value = "PtzsjhServiceImpl")
public class PtzsjhServiceImpl implements PtzsjhService {

    @Autowired
    PtzsjhMapper ptzsjhMapper;

    @Override
    public PageResultful<PageInfo<Ptzsjh>> searchAllPage(PtzsjhModel model) {
        if (null == model) {
            return PageResultful.fail(BasisResultEnum.PARAM_IS_NULL);
        }
        PtzsjhExample example = new PtzsjhExample();
        PtzsjhExample.Criteria criteria = example.createCriteria();
        criteria.andNfEqualTo(model.getNf());
        criteria.andSydEqualTo(model.getSyd());
        PageHelper.startPage(model.getPage(),model.getLimit());
        List<Ptzsjh> ptzsjhs = ptzsjhMapper.selectByExample(example);
        if (ptzsjhs.isEmpty()) {
            return PageResultful.fail(BasisResultEnum.QUERY_IS_NULL);
        }
        PageInfo<Ptzsjh> pageInfo = new PageInfo<>(ptzsjhs);
        return PageResultful.success(pageInfo);
    }

    @Override
    public BasisResultful<Object> searchAll(Ptzsjh ptzsjh) {
        if (null == ptzsjh) {
            return BasisResultful.fail(BasisResultEnum.PARAM_IS_NULL);
        }
        PtzsjhExample example = new PtzsjhExample();
        PtzsjhExample.Criteria criteria = example.createCriteria();
        criteria.andNfEqualTo(ptzsjh.getNf());
        criteria.andSydEqualTo(ptzsjh.getSyd());
        List<Ptzsjh> ptzsjhs = ptzsjhMapper.selectByExample(example);
        if (ptzsjhs.isEmpty()) {
            return BasisResultful.fail(BasisResultEnum.QUERY_IS_NULL);
        }
        return BasisResultful.success(ptzsjhs);
    }
}
